<?php

/**
 * category actions.
 *
 * @package    myarticles
 * @subpackage category
 * @author     Apul Gupta<apulmca2k4@gmail.com>
 */
class categoryActions extends sfActions
{
//  public function executeIndex(sfWebRequest $request)
//  {
//    $this->categorys = CategoryPeer::doSelect(new Criteria());
//  }
//
//  public function executeNew(sfWebRequest $request)
//  {
//    $this->form = new categoryForm();
//  }
//
//  public function executeCreate(sfWebRequest $request)
//  {
//    $this->forward404Unless($request->isMethod(sfRequest::POST));
//
//    $this->form = new categoryForm();
//
//    $this->processForm($request, $this->form);
//
//    $this->setTemplate('new');
//  }
//
//  public function executeEdit(sfWebRequest $request)
//  {
//    $this->forward404Unless($category = CategoryPeer::retrieveByPk($request->getParameter('id')), sprintf('Object category does not exist (%s).', $request->getParameter('id')));
//    $this->form = new categoryForm($category);
//  }
//
//  public function executeUpdate(sfWebRequest $request)
//  {
//    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
//    $this->forward404Unless($category = CategoryPeer::retrieveByPk($request->getParameter('id')), sprintf('Object category does not exist (%s).', $request->getParameter('id')));
//    $this->form = new categoryForm($category);
//
//    $this->processForm($request, $this->form);
//
//    $this->setTemplate('edit');
//  }
//
//  public function executeDelete(sfWebRequest $request)
//  {
//    $request->checkCSRFProtection();
//
//    $this->forward404Unless($category = CategoryPeer::retrieveByPk($request->getParameter('id')), sprintf('Object category does not exist (%s).', $request->getParameter('id')));
//    $category->delete();
//
//    $this->redirect('category/index');
//  }
//
//  protected function processForm(sfWebRequest $request, sfForm $form)
//  {
//    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
//    if ($form->isValid())
//    {
//      $category = $form->save();
//
//      $this->redirect('category/edit?id='.$category->getId());
//    }
//  }

  public function executeShow(sfWebRequest $request)
  {
        $criteria = new Criteria();
        
        if($request->hasParameter('child_slug'))
        {
            $criteria->add(CategoryPeer::URL_SLUG, $request->getParameter('child_slug'));
        }
        else
        {          
            $criteria->add(CategoryPeer::URL_SLUG, $request->getParameter('complete_slug'));
        }

        $this->category = CategoryPeer::doSelectOne($criteria);

        //$this->forward404Unless($this->category);
        $criteria = new Criteria();
        $criteria->add(ArticlePeer::IS_ACTIVE, 1);
        $this->articles = $this->category->getArticleCategorysJoinArticle($criteria);
        $this->limit = sfConfig::get('app_article_search_result');

        
  }

  public function  postExecute() {
      
      $this->getResponse()->setTitle(html_entity_decode($this->category->getMetaTitle()), false);
      $this->getResponse()->addMeta('description', html_entity_decode($this->category->getMetaDescription()));
      $this->getResponse()->addMeta('keywords', html_entity_decode($this->category->getMetaKeyword()));
      
  }
}
